import { extend } from "vee-validate";
import { required } from "vee-validate/dist/rules";

extend("passwordRequired", {
  ...required,
  message: "请输入密码",
});

const passwordReg = /^[a-zA-Z0-9_]{6,18}$/;

extend("password", {
  validate(val) {
    // val就是表单项的值
    // 返回true，代表校验通过
    return passwordReg.test(val);
  },
  message: "密码不合法",
});

const phoneReg = /^1[3-9][0-9]{9}$/;

extend("phone", {
  validate(val) {
    // val就是表单项的值
    // 返回true，代表校验通过
    return phoneReg.test(val);
  },
  message: "手机号不合法",
});

extend("phoneRequired", {
  ...required,
  message: "请输入手机号",
});

export { phoneReg };
